package com.example.springsecuritydemo.controller;

import com.example.springsecuritydemo.model.Users;
import com.example.springsecuritydemo.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/data")
public class UserController {

    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;

    @GetMapping("/test")
    private String data() {
        return "访问成功";
    }


    @ApiOperation("注册用户")
    @PostMapping("/register")
    private String register(@RequestBody Users user) {
        try {
            log.info("------------------------->/register 注册用户开始");
            userService.registerUser(user);
            log.info("------------------------->/register 注册用户结束");
            return "注册用户成功！";
        } catch (Exception e) {
            log.error("------------------------->/register 注册用户异常【{}】", e.getMessage());
            return "注册用户异常" + e.getMessage();
        }
    }
}